import 'package:flutter/material.dart';
import 'package:jd_shopping/services/ScreenAdaper.dart';
import 'package:provider/provider.dart';
import 'package:jd_shopping/pages/CartShop/CartItem.dart';
import 'package:jd_shopping/pages/Providers/CartShow.dart';




class Cart extends StatefulWidget {
  @override
  _CartState createState() => _CartState();
}

class _CartState extends State<Cart> {
   @override
  Widget build(BuildContext context) {
    ScreenAdaper.init(context);
    var cartProvider = Provider.of<CartsShow>(context);
    return Scaffold(
      appBar: AppBar(
        title:Text('购物车'),
        actions: <Widget>[
           IconButton(
            icon: Icon(Icons.launch),
            onPressed:(){
              setState(() {
                cartProvider.removeItem();
              });
            },
          )
        ],
      ),
      body: Stack(
        children: <Widget>[
          ListView(
            children: <Widget>[
             Column(
               children: cartProvider.cartList.map((value) {
                      return CartItem(value);
                 }).toList(),
             )
            ],
          ),
          Positioned(
            bottom: 0,
            height: ScreenAdaper.height(80),
            width: ScreenAdaper.getScreenWidth(),
            child: Container(
              decoration: BoxDecoration(
                border: Border(
                  top: BorderSide(
                    width: 1,
                    color: Colors.black12
                  )
                ),
                 color: Colors.white,
              ),
              width: ScreenAdaper.getScreenWidth(),
              height: ScreenAdaper.height(80),
              child: Stack(
                children: <Widget>[
                   Align(
                    alignment: Alignment.centerLeft,
                    child: Row(
                      children: <Widget>[
                        Container(
                          width: ScreenAdaper.width(60),
                          child: Checkbox(
                            value: cartProvider.isCheckedAll,
                            activeColor: Colors.pink,
                            onChanged: (val) {
                              setState(() {
                                cartProvider.checkAll(val);
                              });
                            },
                          ),
                        ),
                        Text("全选"),
                        SizedBox(width:10),
                        Text("合计："),
                        Text('￥${cartProvider.totalPrice}',style: TextStyle(
                          color:Colors.red,
                          fontSize:20
                        ),),
                      ],
                    ),
                  ),
                   Align(
                     alignment: Alignment.centerRight,
                     child: RaisedButton(
                       child: Text("结算",style: TextStyle(
                         color: Colors.white
                       )),
                       color:Colors.red,
                       onPressed: (){
                          Navigator.pushNamed(context, '/pay');
                       },
                     ),
                  )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}